<?php

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use App\Role;
use Route;

/**
*加载权限板块
*/

class RuleController extends Controller
{
    public static function rule(){
        //获取当前管理员信息
        $rid = session('role');

        //查询出所有该用户的权限
        $role = Role::find($rid);
        //切割
        $temp = explode(',',$role->pid);
        //数据替换
        foreach($temp as $key => $per){
            $data = DB::table('privileges')->select('action')->where('pid',$per)->first();
            $temp[$key] = $data-> action;
        }
        $role->pid = $temp;
        
        //获取当前操作
        /*$route = Route::current();
        $name = $route->getActionName();*/
        $action = Route::currentRouteAction();
        $action = ltrim(strchr($action,'@'),'@');
        //dd(in_array($action, $role->pid));
        
        //判断是否有该操作的权限
        if(!in_array($action, $role->pid)){
            die("没有权限");
        }
    }
}
